<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>测试js语句二</title>
    <script>
        // 2.js的循环语句
        //练习3:假设你有1个亿,每天花500w,能花多少天
        var days = 0; //记录天
        var money = 100000000; //记录钱
        while (money > 0) {
            money -= 5000000; //花钱
            days++; //天数++
        }
        console.log(days);

        //练习2:统计1~100的偶数和
        var sum = 0; //记录和
        for (let i = 1; i <= 100; i++) {
            if (i % 2 == 0) { //过滤偶数
                sum = sum + i; //修改变量
                // sum += i;
            }
        }
        console.log(sum);
        //练习1:打印1~100
        for (let i = 1; i <= 100; i++) {
            console.log(i);
        }
        // 1.js的变量和常量
        var a = 2; //变量
        a = 'hello';
        console.log(a); //hello

        const b = 10; //常量,值不能再改
        // b = 20;
        console.log(b);

        let c = 10; //变量,有作用域
        c = 20;
        console.log(c);

        var x = 10; {
            let x = 20; //只在{}内有效,出去就无效了
            console.log("x=" + x); //20
        }
        console.log("x=" + x); //10
    </script>
</head>

<body>
</body>

</html>